﻿

function Product(data) {
	this.id = ko.observable(data.$id);
	this.ProductId = ko.observable(data.ProductId);
	this.Name = ko.observable(data.Name).extend({ required: true }) ;
	this.Color = ko.observable(data.Color);
	this.Brand = ko.observable(data.Brand);
	this.Quantity = ko.observable(data.Quantity).extend({ required: true ,
	    number: true
    });
	this.Price = ko.observable(data.Price).extend({ required: true,
	    number: true
	});
	this.ActualCost = ko.observable(data.ActualCost).extend({ required: true,
	    number: true
	});
	this.PriceView = ko.computed(function () {
		return numeral(this.Price()).format('0,0');
	}, this);
	this.ActualCostView = ko.computed(function () {
		return numeral(this.ActualCost()).format('0,0');
	}, this);
    this.Warranty = ko.observable(data.Warranty).extend({ required: true,
        number: true
    });
      
    
	this.Promotion = ko.observable(data.Promotion);
	this.IsDelete = ko.observable(data.IsDelete);
	this.Image = ko.observable(data.Image);
	this.IsUsed = ko.observable(data.IsUsed);
	this.CommingSoon = ko.observable(data.CommingSoon);
	this.Arrive = ko.observable(data.Arrive);
	this.Type = ko.observable(data.Type);
	this.Block = ko.observable(data.Block);
	this.ImageNormal = ko.computed(function () {
		return '../../Content/phones/img-products-' + this.Image() + '-175x0.jpg';
	}, this);
	this.ImageSmall = ko.computed(function () {
		return '../../Content/phones/img-products-' + this.Image() + '-175x0.jpg';
	}, this);
	this.ImageBig = ko.computed(function () {
		return '../../Content/phones/img-products-' + this.Image() + '-175x0.jpg';
    }, this);
    
}

function Cart(data) {
	this.RecordId = ko.observable(data.RecordId);
	this.Count = ko.observable(data.Count).extend({ number: true , min: 1, max:99 });
	this.ProductName = ko.observable(data.Product.Name);
	this.ProductPrice = ko.observable(data.Product.Price);
	this.ProductPriceView = ko.computed(function () {
		return numeral(this.ProductPrice()).format('0,0');
	}, this);
	this.CartTotal = ko.computed(function () {
		var cartTotal = this.ProductPrice() * this.Count();
		return numeral(cartTotal).format('0,0');
	}, this);

	this.getCartTotal = function() {
		var cartTotal = this.ProductPrice() * this.Count();
		return cartTotal;
	};

	this.ImageSmall = ko.computed(function () {
		return '../../Content/phones/img-products-' + data.Product.Image + '-175x0.jpg';
	}, this);
}
